<?php

class PublicAction extends Action{
	private $sid;
	private $groupid;
	function _initialize()
	{
		$this->sid=Session::get(C('USER_AUTH_KEY'));
		$this->groupid=Session::get('groupid');
	}

	public function login()
	{
		//if(!isset($this->sid) || $groupid!=1 || $groupid!=2)
		if(!isset($this->sid) || $this->groupid=='')
		{
			$this->display();
		}else{
			$this->redirect('Index/index');
		}
	}
	/**
	 * 登陆检测
	 * 
	 * 修改注释:
	 * 修改标识: 孙强 2012-3-30 14:57:02
	 * 修改内容: redirect跳转
	 * 
	 */	
	public function checkLogin()
	{
		$Member=D('Member');
		$username=trim(dhtml($_POST['username']));
		$password=trim(dhtml($_POST['password']));
		$seccode=trim($_POST['seccode']);
		if($username=='')
		{
			$this->error('用户名不能为空!!!');
		}elseif($password==''){
			$this->error('密码不能为空!!!');
		}
 		elseif(md5($seccode)!=Session::get('verify')){
 			$this->error('验证码错误!!!');
 		}
		$map=array();
		$map["username"]=$username;
		$user=$Member->find($map);
		if(false===$user)
		{
			$this->error('用户名不存在!!!');
		}else{
			if($user['password']!=md5($password))$this->error('密码错误!!!');
			if($user['ischecked']!=1)$this->error('用户被锁定');
			if($user['groupid']==2)$this->error('用户组被限制登录系统，请联系管理员');
				Session::set(C('USER_AUTH_KEY'),$user['id']);
				Session::set('username',$user['username']);
				Session::set('groupid',$user['groupid']);
				$this->redirect('Index/index');

		}
	}


	/**
	 * 
	 * 验证码显示
	 * 
	 */
	function verify()
	{
		import('Think.Util.Image');
		//$length=4,$mode=1,$type='png',$width=48,$height=22,$verifyName='verify'
//		Image :: buildImageVerify(5,1,'png',60,19,'verify');
		if(isset($_REQUEST['adv']))
		{
			Image::showAdvVerify();
		}
		else
		{
			Image::buildImageVerify();
		}
	}

	public function authorizationstop() 
	{
		$this->display();
	}
	public function logout() 
    {
        if(isset($this->sid)) {
			Session::destroy();
            $this->assign("message",'登出成功!!!');
//            $this->assign("jumpUrl",__APP__.'/Public/login/');
            $this->redirect('Public/login');
        }else {
            $this->assign('error', '已经登出！');
        }
        $this->forward();
    }
}
?>